//***************common.js start***************
function IsDate(DateString, Dilimeter) {
	if (DateString == null) {
		return false;
	}
	if (Dilimeter == "" || Dilimeter == null) {
		Dilimeter = "-";
	}
	var tempy = "";
	var tempm = "";
	var tempd = "";
	var tempArray;
	if (DateString.length < 8 && DateString.length > 10) {
		return false;
	}
	tempArray = DateString.split(Dilimeter);
	if (tempArray.length != 3) {
		return false;
	}
	if (tempArray[0].length == 4) {
		tempy = tempArray[0];
		tempd = tempArray[2];
	} else {
		tempy = tempArray[2];
		tempd = tempArray[1];
	}
	tempm = tempArray[1];
	var tDateString = tempy + "/" + tempm + "/" + tempd + " 8:0:0";
	var tempDate = new Date(tDateString);
	if (isNaN(tempDate)) {
		return false;
	}
	if (((tempDate.getUTCFullYear()).toString() == tempy) && (tempDate.getMonth() == parseInt(tempm, 10) - 1) && (tempDate.getDate() == parseInt(tempd, 10))) {
		return true;
	} else {
		return false;
	}
}
function isDateString(str) {
	var reg = /^\d{4}-[0-1]?\d{1}-[0-3]?\d{1}$/;
	return reg.test(str);
}
function stringToDate(sDate, bIgnore) {
	var bValidDate, year, month, day;
	var iaDate = new Array(3);
	if (bIgnore) {
		bValidDate = true;
	} else {
		bValidDate = isDateString(sDate);
	}
	if (bValidDate) {
		iaDate = sDate.toString().split("-");
		year = parseFloat(iaDate[0]);
		month = parseFloat(iaDate[1]) - 1;
		day = parseFloat(iaDate[2]);
		return (new Date(year, month, day));
	} else {
		return (new Date(1900, 1, 1));
	}
}



//去掉字串两端的空格
function trim(str) {
	var SubStr;
	SubStr = str;
	while (SubStr.length > 0) {
		if (SubStr.charAt(0) == " ") {
			SubStr = SubStr.slice(1);
		} else {
			if (SubStr.charAt(0) == "\u3000") {
				SubStr = SubStr.slice(1);
			} else {
				break;
			}
		}
	}
	while (SubStr.length > 0) {
		if (SubStr.charAt(SubStr.length - 1) == " ") {
			SubStr = SubStr.substr(0, SubStr.length - 1);
		} else {
			break;
		}
	}
	return SubStr;
}



// 比较date1和date2: date1大于date2返回1, 相等返回0, 小于返回-1.
function CompareDate(date1, date2) {
	var dt1 = RebuildDate(date1);
	var dt2 = RebuildDate(date2);
	if (dt1 > dt2) {
		return (1);
	} else {
		if (dt1 == dt2) {
			return (0);
		} else {
			return (-1);
		}
	}
}
function RebuildDate(val) {
	var date_array = "";
	var get_input_date_str = val;
	var seperate;
	if (get_input_date_str == "") {
		return true;
	}
	if (get_input_date_str.indexOf("-") != -1) {
		seperate = "-";
	} else {
		if (get_input_date_str.indexOf("/") != -1) {
			seperate = "/";
		} else {
			if (get_input_date_str.indexOf(".") != -1) {
				seperate = ".";
			}
		}
	}
	date_array = get_input_date_str.split(seperate);
	if (date_array.length != 3) {
		return "";
	}
	if (date_array[0].length < 4) {
		return "";
	}
	date_array[1] = date_array[1] - 1;
	var get_input_date = new Date(date_array[0], date_array[1], date_array[2]);
	var dt = DateToStr(get_input_date);
	return dt;
}
function DateToStr(get_input_date) {
	get_input_date.setHours(8);
	var get_input_year = get_input_date.getUTCFullYear();
	var get_input_month = get_input_date.getMonth() + 1;
	var get_input_day = get_input_date.getDate();
	if (get_input_year < 1000) {
		get_input_year = 1900 + get_input_year;
	}
	if (get_input_month < 10) {
		get_input_month = "0" + get_input_month;
	}
	if (get_input_day < 10) {
		get_input_day = "0" + get_input_day;
	}
	var dt = get_input_year + "-" + get_input_month + "-" + get_input_day;
	return dt;
}
function CompareToday(date1) {
	var dt1 = RebuildDate(date1);
	var dt2 = TodayToStr();
	var todayObj = document.getElementById("servertoday");
	if (todayObj == null) {
	} else {
		dt2 = todayObj.value;
	}
	if (dt1 > dt2) {
		return (1);
	} else {
		if (dt1 == dt2) {
			return (0);
		} else {
			return (-1);
		}
	}
}
function TodayToStr() {
	var dt = new Date();
	var str = DateToStr(dt);
	return str;
}
function TomorrowToStr() {
	var dt = new Date().getTime() + 24 * 60 * 60 * 1000;
	var tdt = new Date(dt);
	var str = DateToStr(tdt);
	return str;
}
function nextDayToStr(date) {
	var dt = stringToDate(date).getTime() + 24 * 60 * 60 * 1000;
	var tdt = new Date(dt);
	var str = DateToStr(tdt);
	return str;
}

//***************common.js end*****************

//***********************model.js start***************************
if (window.HTMLElement) {
	HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var df = r.createContextualFragment(sHTML);
		this.parentNode.replaceChild(df, this);
		return sHTML;
	});
	HTMLElement.prototype.__defineGetter__("outerHTML", function () {
		var attr;
		var attrs = this.attributes;
		var str = "<" + this.tagName;
		for (var i = 0; i < attrs.length; i++) {
			attr = attrs[i];
			if (attr.specified) {
				str += " " + attr.name + "=\"" + attr.value + "\"";
			}
		}
		return str + ">" + this.innerHTML + "</" + this.tagName + ">";
	});
}
Array.prototype.unZipModel = function (zipstring, iterator) {
	var pairs = zipstring.split(";");
	for (var i = 0; i < pairs.length; i++) {
		var pair = pairs[i].split("|");
		this.push(iterator(pair, i));
	}
};
function exist(id) {
	var s = document.getElementById(id);
	if (s) {
		return true;
	} else {
		return false;
	}
}





//新的校验方法(Ajax输入框)
function CheckSearchFormNew() {
	var datestr = "-";
	clearerrormsg();
	var dStartInput = trim(document.getElementById("cfromCity").value);
	var LastStartInput = trim(document.getElementById("ctoCity").value);
	//var dStart2Input = trim(document.getElementById("cfromCity3").value);
	//var LastStart2Input = trim(document.getElementById("ctoCity3").value);
	var FlyDate = document.getElementById("fromdate").value;
	//var FlyDate2 = document.getElementById("todate").value;
	var ReturnDate = document.getElementById("todate").value;
	//var outcityInput = trim(document.getElementById("coutTicketCity").value);
	var rtn = true;
	rtn = CheckTestCity();
	
	if(rtn==false){
		return false;
	}
	rtn = rtn&&CheckFlyDate();
	if(rtn==false){
		return false;
	}
	var vt = $("#voyageTypevalue").val();
	
	/*if (vt == "2") {
		rtn = CheckRoundTrip();
		if(rtn==false){
		return false;
	}
	} else {
	if (vt == "1") {}
	else {rtn = false;}
	}*/
	return rtn;



    //------------------------------
	function CheckTestCity() {
		if (dStartInput == "中文/拼音" ||dStartInput == "" || dStartInput == null) {
			$("#cfromCity").after(errMsg(FLIGHT_AJAX_NODEPARTURECITY));
			$("#cfromCity").addClass("onFormError");
			document.getElementById("cfromCity").value = "";
			document.getElementById("cfromCity").focus();
			return false;
		}else{
			if(GetCityCodeByName(dStartInput)==null){
		
			 $("#cfromCity").after(errMsg("请输入有机场的城市名。"));
			 $("#cfromCity").addClass("onFormError");
			document.getElementById("cfromCity").value = "";
			document.getElementById("cfromCity").focus();
			return false;
			}
		}
		if (LastStartInput == "中文/拼音" ||LastStartInput == "" || LastStartInput == null) {
			$("#ctoCity").after(errMsg(FLIGHT_AJAX_NODESTCITY));
			$("#ctoCity").addClass("onFormError");
			document.getElementById("ctoCity").value = "";
			document.getElementById("ctoCity").focus();
			return false;
		}else{
			if(GetCityCodeByName(LastStartInput)==null){
			 $("#ctoCity").after(errMsg("请输入有机场的城市名。"));
			$("#ctoCity").addClass("onFormError");
			document.getElementById("ctoCity").value = "";
			document.getElementById("ctoCity").focus();
			return false;
			}
		}
		if (dStartInput == LastStartInput) {
			$("#ctoCity").after(errMsg(FLIGHT_REQUEST_SAMECITY));
			$("#ctoCity").addClass("onFormError");
			document.getElementById("ctoCity").value = "";
			document.getElementById("ctoCity").focus();
			return false;
		}
		/*if (outcityInput == "中文/拼音" ||outcityInput == "" || outcityInput == null) {
			$("#coutTicketCity").after(errMsg(FLIGHT_AJAX_NOOUTCITY));
			$("#coutTicketCity").addClass("onFormError");
			document.getElementById("coutTicketCity").value = "";
			document.getElementById("coutTicketCity").focus();
			return false;
		}else{
			if(GetCityCodeByName(outcityInput)==null){
			 $("#coutTicketCity").after(errMsg("请输入有机场的城市名。"));
			 $("#coutTicketCity").addClass("onFormError");
			document.getElementById("coutTicketCity").value = "";
			document.getElementById("coutTicketCity").focus();
			return false;
			}
		}*/
		return true;
	}
	function CheckFlyDate() {
		if (!IsDate(FlyDate, "-") && !IsDate(FlyDate, "/")) {
			$("#fromdate").after(errMsg(FLIGHT_FLYDATE_FORMAT));
			$("#fromdate").addClass("onFormError");
			document.getElementById("fromdate").focus();
			return false;
		}
		return true;
	}
	function CheckRoundTrip() {
		if (ReturnDate == null || ReturnDate == "") {
			$("#todate").after(errMsg(FLIGHT_RETURNDATE_NULL));
			$("#todate").addClass("onFormError");
			document.getElementById("todate").focus();
			return false;
		}
		if (!IsDate(ReturnDate, "-") && !IsDate(ReturnDate, "/")) {
			$("#todate").after(errMsg(FLIGHT_RETURNDATE_FORMAT));
			$("#todate").addClass("onFormError");
			document.getElementById("todate").focus();
			return false;
		} else {
			if($(".search_ss2").attr("disabled")==false){
			if (CompareDate(FlyDate, ReturnDate) > 0) {
				$("#todate").after(errMsg(FLIGHT_REQUEST_AHEADBACKDATE));
				$("#todate").addClass("onFormError");
				document.getElementById("todate").focus();
				return false;
			}}
		}
		return true;
	}
	function CheckMultiple() {
		if (LastStart2Input == dStart2Input && (LastStart2Input != "" || dStart2Input != "")) {
			$("#cfromCity3").after(errMsg(FLIGHT_REQUEST_SECONDSAMELEAVE));
			$("#cfromCity3").addClass("onFormError");
			document.getElementById("cfromCity3").value = "";
			document.getElementById("cfromCity3").focus();
			return false;
		}
		if (!IsDate(FlyDate2, "-") && !IsDate(FlyDate2, "/")) {
			$("#fromdate3").after(errMsg(FLIGHT_REQUEST_SECONDLEAVEDATE_FORMAT));
			$("#fromdate3").addClass("onFormError");
			document.getElementById("fromdate3").focus();
			return false;
		} else {
			if (CompareDate(FlyDate, FlyDate2) > 0) {
				$("#fromdate3").after(errMsg(FLIGHT_REQUEST_AHEADSECONDLEAVEDATE));
				$("#fromdate3").addClass("onFormError");
				document.getElementById("fromdate3").focus();
				return false;
			} else {
				if (FlyDate == FlyDate2) {
				}
			}
		}
		if (dStart2Input == "中文/拼音" ||dStart2Input == "" || dStart2Input == null) {
			$("#cfromCity3").after(errMsg(FLIGHT_AJAX_NODEPARTURECITY));
			$("#cfromCity3").addClass("onFormError");
			document.getElementById("cfromCity3").value = "";
			document.getElementById("cfromCity3").focus();
			return false;
		}else{
			if(GetCityCodeByName(dStart2Input)==null){
			 $("#cfromCity3").after(errMsg("请输入有机场的城市名。"));
			 $("#cfromCity3").addClass("onFormError");
			document.getElementById("cfromCity3").value = "";
			document.getElementById("cfromCity3").focus();
			return false;
			}
		}
		if (LastStart2Input == "中文/拼音" ||LastStart2Input == "" || LastStart2Input == null) {
			$("#ctoCity3").after(errMsg(FLIGHT_AJAX_NODESTCITY));
			$("#ctoCity3").addClass("onFormError");
			document.getElementById("ctoCity3").value = "";
			document.getElementById("ctoCity3").focus();
			return false;
		}else{
			if(GetCityCodeByName(LastStart2Input)==null){
			 $("#ctoCity3").after(errMsg("请输入有机场的城市名。"));
			 $("#ctoCity3").addClass("onFormError");
			document.getElementById("ctoCity3").value = "";
			document.getElementById("ctoCity3").focus();
			return false;
			}
		}
		return true;
	}
}







//***************ScriptText.js start***************
var FLIGHT_REQUEST_SAMECITY = "\u51fa\u53d1\u57ce\u5e02\u4e0e\u5230\u8fbe\u57ce\u5e02\u4e0d\u53ef\u76f8\u540c\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01";
var FLIGHT_REQUEST_AHEADLEAVEDATE = "\u51fa\u53d1\u65e5\u671f\u4e0d\u53ef\u65e9\u4e8e\u4eca\u65e5\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9";
var FLIGHT_REQUEST_AHEADLEAVEDATE_LIMIT = "\u51fa\u53d1\u65e5\u671f\u8d85\u51fa\u9650\u5236\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\uff01";
var FLIGHT_REQUEST_RETURNDATELIMIT = "\u8fd4\u7a0b\u65e5\u671f\u8d85\u51fa\u9650\u5236\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\uff01";
var FLIGHT_RETURNDATE_FORMAT = "\u8fd4\u7a0b\u65e5\u671f\u586b\u5199\u6709\u8bef\uff0c\u6b63\u786e\u683c\u5f0f\u4e3ayyyy-mm-dd";
var FLIGHT_REQUEST_AHEADBACKDATE = "\u8fd4\u7a0b\u65e5\u671f\u4e0d\u53ef\u65e9\u4e8e\u51fa\u53d1\u65e5\u671f\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\uff01";
var FLIGHT_REQUEST_AHEADBACKTIME = "\u8fd4\u7a0b\u7684\u51fa\u53d1\u65f6\u95f4\u4e0d\u53ef\u65e9\u4e8e\u53bb\u7a0b\u7684\u51fa\u53d1\u65f6\u95f4\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\uff01";
var FLIGHT_REQUEST_SECONDSAMELEAVE = "\u7b2c\u4e8c\u822a\u7a0b\u51fa\u53d1\u57ce\u5e02\u4e0e\u7b2c\u4e8c\u822a\u7a0b\u5230\u8fbe\u57ce\u5e02\u4e0d\u53ef\u76f8\u540c\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01";
var FLIGHT_REQUEST_SECONDLEAVEDATE_LIMIT = "\u7b2c\u4e8c\u822a\u7a0b\u51fa\u53d1\u65e5\u671f\u8d85\u51fa\u9650\u5236\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\uff01";
var FLIGHT_REQUEST_SECONDLEAVEDATE_FORMAT = "\u7b2c\u4e8c\u822a\u7a0b\u51fa\u53d1\u65e5\u671f\u586b\u5199\u6709\u8bef\uff0c\u6b63\u786e\u683c\u5f0f\u4e3ayyyy-mm-dd\uff01";
var FLIGHT_REQUEST_SECONDAHEADFIRSTDATE = "\u7b2c\u4e8c\u822a\u7a0b\u7684\u51fa\u53d1\u65f6\u95f4\u4e0d\u53ef\u65e9\u4e8e\u7b2c\u4e00\u822a\u7a0b\u7684\u51fa\u53d1\u65f6\u95f4\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\uff01";
var FLIGHT_REQUEST_AHEADSECONDLEAVEDATE = "\u7b2c\u4e8c\u822a\u7a0b\u7684\u51fa\u53d1\u65f6\u95f4\u4e0d\u53ef\u665a\u4e8e\u4e8e\u7b2c\u4e00\u822a\u7a0b\u7684\u51fa\u53d1\u65f6\u95f4\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9\uff01";
var FLIGHT_AJAX_NODEPARTURECITY = "\u8bf7\u8f93\u5165\u51fa\u53d1\u57ce\u5e02\uff01";
var FLIGHT_AJAX_INVALIDDEPARTURECITY = "\u65e0\u6b64\u51fa\u53d1\u57ce\u5e02\uff01";
var FLIGHT_AJAX_NODESTCITY = "\u8bf7\u8f93\u5165\u5230\u8fbe\u57ce\u5e02\uff01";
var FLIGHT_AJAX_INVALIDDESTCITY = "\u65e0\u6b64\u5230\u8fbe\u57ce\u5e02\uff01";
var FLIGHT_FLYDATE_FORMAT = "\u51fa\u53d1\u65e5\u671f\u586b\u5199\u6709\u8bef\uff0c\u6b63\u786e\u683c\u5f0f\u4e3ayyyy-mm-dd";
var FLIGHT_RETURNDATE_NULL = "\u8fd4\u7a0b\u65e5\u671f\u4e0d\u80fd\u4e3a\u7a7a\u3002";
var FLIGHT_AJAX_NOOUTCITY = "\u8bf7\u8f93\u5165\u51fa\u7968\u57ce\u5e02\uff01";
var FLIGHT_AJAX_INVALIDOUTCITY = "\u65e0\u6b64\u51fa\u7968\u57ce\u5e02\uff01";
function SetCalendarOptions(e, element, language) {
	e.cancelBubble = true;
	new CalendarWindow({eventElement:element, language:language, onSelected:function (date) {
		$(element).attr("value", date);
	}.bind(this)});
}
function errMsg(errmsg) {
	msg_frame = "<div class=\"errorBottomPrompt ticketerrmsg\">" + "<div class=\"pmt\">" + "<p>" + errmsg + "</p>" + "<div class=\"inArr\"></div>" + "</div>" + "</div>";
	return msg_frame;
}
function clearerrormsg() {
	$(".ticketerrmsg").each(function () {
		$(this).remove();
	});
	$(".onFormError").each(function () {
		$(this).removeClass('onFormError');
	});
}

